package com.cardbaobao.cardbabyclient.model;

import android.os.Build;
import com.cardbaobao.cardbabyclient.utils.ApplicationHelper;
import com.cardbaobao.cardbabyclient.utils.SharedPreferencesUtil;
import com.ta.utdid2.device.UTDevice;

/**
 * Created by Jiangzx on 2017/11/10 10:16.
 * 数据埋点工具类
 */

public class BuriedData {
    private static volatile BaseData baseData;

    //清除掉与用户登录后才能有的相关信息
    public static void initBaseData(){
        if(baseData==null){
            synchronized (BuriedData.class){
                if(baseData==null){
                    baseData=new BaseData();
                }
            }
        }
        baseData.temporary_id= SharedPreferencesUtil.PhoneInfo.getTemporaryId();
        UserInfo userInfo= ApplicationHelper.getApplication().getUser();
        int userId=userInfo.getID();
        baseData.regist_id=userId==0?"":String.valueOf(userId);
        baseData.city= SharedPreferencesUtil.LocationInfo.getCityName();
        baseData.phone_number=userInfo.getPhone();
        baseData.cell_phone_model= Build.MODEL;
        baseData.utdid= UTDevice.getUtdid(ApplicationHelper.getApplicationContext());
    }

    public static class BaseData{
        private String temporary_id;
        private String regist_id;
        private String city;
        private String end_user="mobile";//mobile
        private String phone_number;
        private String cell_phone_model;
        private String cell_phone_system="Android";//Android
        private String channel="APP";//APP
        private String location;//"经度，纬度"
        private String signal_mode;//WIFI,GPRS
        private String utdid;

        public String getLocation() {
            return location;
        }

        public void setLocation(String location) {
            this.location = location;
        }

        public String getSignal_mode() {
            return signal_mode;
        }

        public void setSignal_mode(String signal_mode) {
            this.signal_mode = signal_mode;
        }

        public String getTemporary_id() {
            return temporary_id;
        }

        public void setTemporary_id(String temporary_id) {
            this.temporary_id = temporary_id;
        }

        public String getRegist_id() {
            return regist_id;
        }

        public void setRegist_id(String regist_id) {
            this.regist_id = regist_id;
        }

        public String getCity() {
            return city;
        }

        public void setCity(String city) {
            this.city = city;
        }

        public String getEnd_user() {
            return end_user;
        }

        public String getPhone_number() {
            return phone_number;
        }

        public void setPhone_number(String phone_number) {
            this.phone_number = phone_number;
        }

        public String getCell_phone_model() {
            return cell_phone_model;
        }

        public String getChannel() {
            return channel;
        }

        public String getCell_phone_system() {
            return cell_phone_system;
        }

        public String getUtdid() {
            return utdid;
        }

        public void setUtdid(String utdid) {
            this.utdid = utdid;
        }
    }

    public static class ClickData{
        private String action_id;
        private String action_name;
        public ClickData(String action_id,String action_name){
            this.action_id=action_id;
            this.action_name=action_name;
        }
        public String getAction_id() {
            return action_id;
        }

        public void setAction_id(String action_id) {
            this.action_id = action_id;
        }

        public String getAction_name() {
            return action_name;
        }

        public void setAction_name(String action_name) {
            this.action_name = action_name;
        }
    }

    public static class BrowseData{
        private String page_retain;//页面停留时间
        private String currentpage_id;//页面id
        private String prepage_id;//上一个页面的id

        public BrowseData(){

        }

        public BrowseData(long enterPageTime,
                          String currentpage_id,
                          String prepage_id) {
            this.page_retain = String.valueOf((System.currentTimeMillis()-enterPageTime)/1000);
            this.currentpage_id = currentpage_id;
            this.prepage_id = prepage_id;
        }

        public String getPage_retain() {
            return page_retain;
        }

        public void setPage_retain(String page_retain) {
            this.page_retain = page_retain;
        }

        public String getCurrentpage_id() {
            return currentpage_id;
        }

        public void setCurrentpage_id(String currentpage_id) {
            this.currentpage_id = currentpage_id;
        }

        public String getPrepage_id() {
            return prepage_id;
        }

        public void setPrepage_id(String prepage_id) {
            this.prepage_id = prepage_id;
        }
    }

    public static class PostData{
        private BaseData base_data;
        private ClickData click_data;
        private BrowseData browse_data;

        public PostData(){
            initBaseData();
            this.base_data=baseData;
        }

        public BaseData getBase_data() {
            return base_data;
        }

        public void setBase_data(BaseData base_data) {
            this.base_data = base_data;
        }

        public ClickData getClick_data() {
            return click_data;
        }

        public void setClick_data(ClickData click_data) {
            this.click_data = click_data;
        }

        public BrowseData getBrowse_data() {
            return browse_data;
        }

        public void setBrowse_data(BrowseData browse_data) {
            this.browse_data = browse_data;
        }
    }
}
